package model

import (
	"DouBan/utils"
	"gorm.io/gorm"
)

type User struct {
	Id uint `json:"id" gorm:"primaryKey;autoIncrement"`
	//Uid         string `json:"uid" gorm:"primaryKey;unique;column:uid;type:varchar(32)"`
	UserName    string `json:"user_name" gorm:"column:user_name;uniqueIndex;type:varchar(32)"`
	PassWord    string `json:"pass_word" gorm:"column:pass_word;type:varchar(32)"`
	Email       string `json:"email" gorm:"column:email;type:varchar(32)"`
	CreatedTime string `json:"created_time" gorm:"column:created_time;type:varchar(20)"`
	UpdateTime  string `json:"update_time" gorm:"column:update_time;type:varchar(20)"`
}

func (u User) TableName() string {
	return "user"
}

func (u *User) BeforeSave(tx *gorm.DB) error {
	nowTimeStr := utils.GetNowTimeStr()
	if u.CreatedTime == "" {
		u.CreatedTime = nowTimeStr
	}
	u.UpdateTime = nowTimeStr
	return nil
}
